from pyutils import get_GET_ret, mytest_api, mytest_f_speed, data_to_json, add_slash_to_url, json_to_dict
# from tools import *
import json
import requests

localhost = 'http://127.0.0.1:8000'

local_headers = {
    'Content-Type': 'application/json',
    'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyOCwidXNlcm5hbWUiOiIxODUxMDc3OTEwMiIsImV4cCI6MTYyMjE4MjkyNSwiZW1haWwiOm51bGwsIm9yaWdfaWF0IjoxNjE2OTk4OTI1fQ.fC33BRfy9nPqVMmVchJQ9QKNOkD6zQIenT_6lYPvk2M',
}


class TestClass:
    def test_draw_local(self):
        url_0 = f'/api/exam/check_answer/'
        url_0 = localhost + url_0

        # resp = get_GET_ret(url_0, headers=local_headers)
        post_data_1 = {
            "question_type": "单选",
            "question_id": 70,
            "answer": "a",
        }
        post_data_2 = {
            "question_type": "判断",
            "question_id": 2,
            "answer": "b",
        }

        post_data_s = {
            # "user_id": 110,
            # 'data': [post_data_0, post_data_1, post_data_2, post_data_3, post_data_4],
            'data': [post_data_1, post_data_2],
        }

        post_data = post_data_s
        print(post_data)
        print(url_0)
        print('题目数量: ', len(post_data.get('data')))
        print('---------------  post方法测试结果:')
        post_data = data_to_json(post_data)
        url_0 = add_slash_to_url(url_0)

        resp = requests.post(url_0, post_data, headers=local_headers)


        print(f'*** resp: {resp}')
        resp_data = json.loads(resp.content)
        print(resp_data)
        assert resp_data.get('status') == 200, "状态码返回错误!"




        # res = resp.get('result')
        # print('~~~ res: ', res)

